package com.purchase.ml.service.email.order;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.purchase.ml.bean.req.mail.MailMessage;
import com.purchase.ml.consts.Constants;
import com.purchase.ml.consts.MailConstants;
import com.purchase.ml.entity.acc.SysUser;
import com.purchase.ml.entity.dealer.SysAddr;
import com.purchase.ml.entity.dealer.SysDealer;
import com.purchase.ml.entity.order.SysOrder;
import com.purchase.ml.entity.order.SysOrderDetail;
import com.purchase.ml.entity.prod.SysProduct;
import com.purchase.ml.entity.prod.SysProductSku;
import com.purchase.ml.mapper.dealer.SysAddrMapper;
import com.purchase.ml.mapper.dealer.SysDealerMapper;
import com.purchase.ml.mapper.order.SysOrderDetailMapper;
import com.purchase.ml.mapper.prod.SysProdSkuMapper;
import com.purchase.ml.mapper.sys.SysUserMapper;
import com.purchase.ml.service.prod.SysProdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;

/**
 * @author :zxm
 * @date :2021/3/23 16:44
 * @description :商户下订单后，发送的邮件
 **/
@Component
public class OrderEmail {
    @Value("${mail.content.sysAddress:https://www.baidu.com/}")
    private String sysAddress;
    @Value("${mail.content.generalEmail:123456@qq.com}")
    private String generalEmail;
    @Value("${mail.content.problemUrl}")
    private String problemUrl;
    @Value("${mail.content.imgAddress}")
    private String imgAddress;

    @Autowired
    private SysDealerMapper sysDealerMapper;
    @Autowired
    private SysAddrMapper sysAddrMapper;
    @Autowired
    private SysOrderDetailMapper sysOrderDetailMapper;
    @Autowired
    private SysProdService sysProdService;
    @Autowired
    private SysProdSkuMapper sysProdSkuMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     *  主经销商下单后系统会发送 “新采购订单通知” 的邮件至持有者
     * @param sysOrder 采购订单
     * @return MailMessage
     * 调用方式：RedisClient.lpush(MailConstants.REDIS_MAIL_MESSAGE,MailMessage);
     */
    public MailMessage getSendMdealerPurMsg(SysOrder sysOrder){
        // 获取商户
        SysDealer masterDealer = sysDealerMapper.selectByDealerId(sysOrder.getBuyer());
        SysDealer agentDealer = sysDealerMapper.selectByDealerId(sysOrder.getSellers());
        // 通过经销商id查询用户
//        SysUser agentUser = sysUserMapper.selectByDealerId(agentDealer.getDealerId());

        MailMessage mailMessage = new MailMessage();
        mailMessage.setSubject("Purchase Order from Master Dealer");
        mailMessage.setEmail(agentDealer.getEmailAddress());
        String content = "<div id=\"editbody1\">\n" +
                "    <div style=\"font-size: 10pt; font-family: Verdana,Geneva,sans-serif;\">\n" +
                "        <div id=\"Evo_Oil_Email_Template_web_guide\" style=\"position: absolute; width: 1032px; height: 1080px; background-color: rgba(255, 255, 255, 1); overflow: hidden; --web-view-name: Evo Oil Email Template_web_guide; --web-view-id: Evo_Oil_Email_Template_web_guide; --web-scale-on-resize: true; --web-enable-deep-linking: true;\">\n" +
                "            <div id=\"header\" style=\"text-align: center;\"><img id=\"evo_oil_logo\" style=\"position: absolute; width: 94.26px; height: 86px; left: 44.5%; top: 23px; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/evo_oil_logo.a4e120fb.png\" /></div>\n" +
                "            <img id=\"img_login\" style=\"position: absolute; width: 812px; height: 272px; left: 9.7%; top: 136px; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/img_home_banner.981ba427.jpg\" />\n" +
                "            <div id=\"email_content\" style=\"position: absolute; width: 536px; height: 473px; left: 12%; top: 458px; overflow: visible;\"><br /><br />\n" +
                "                <div id=\"Hello__name_\" style=\"left: 0px; top: 0px; position: absolute; overflow: visible; width: 114px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Hello "+ agentDealer.getDealerName() +",</span></div>\n" +
                "                <br />\n" +
                "                <br />\n" +
                "                <div id=\"You_have_registered_as_a_deale\" style=\"left: 0px; top: 81px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>You have just received a purchase order from master dealer "+ masterDealer.getDealerName() +".<br />Click on the button below to check the purchase order details.</span></div>\n" +
                "                <br /><br />\n" +
                "                <div id=\"btn\" style=\"position: absolute; width: 203px; height: 50px; left: 0px; top: 164px; overflow: visible;\">\n" +
                "                    <div id=\"Verify_Your_Email\" class=\"__web-inspector-hide-shortcut__\"><a href=\""+ sysAddress +"\" target=\"_blank\" rel=\"noopener noreferrer\"><button style=\"top: 622px; left: 500px; width: 203px; height: 50px; background: #FDB500 0% 0% no-repeat padding-box; text-align: center; border-radius: 30px; opacity: 1; font: normal normal bold 16px/19px Roboto; font-size: 16px; color: #ffffff;\">View Purchase Order</button></a></div>\n" +
                "                </div>\n" +
                "                <br />\n" +
                "                <div id=\"If_you_have_problems_please_co\" style=\"left: 0px; top: 234px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>If you have problems, please copy and paste the below URL into your web browser. <br /><br />"+ problemUrl +"<br /><br />Need help? Contact us at <a href=\"mailto:careline@evooil.com.my\">"+ generalEmail +"</a> <br /><br />Thank you.</span></div>\n" +
                "                <br /><br /><br /><br />\n" +
                "                <div id=\"Best_Regards_Evo_Oil_Dealershi\" style=\"left: 0px; top: 432px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; line-height: 20px; margin-top: -1px; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Best Regards,</span><br /><span style=\"font-style: normal; font-weight: bold;\">Evo Oil Dealership System</span></div>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "</div>";
        mailMessage.setText(content);
        mailMessage.setType(MailConstants.ORDER_TYPE);
        return mailMessage;
    }

    /**
     *  主经销商下单后  系统会发送 “已接受采购订单” 以及采购订单的详情相关的邮件至主经销商
     * @param order  采购的订单信息
     * @return MailMessage
     * 调用方式：RedisClient.lpush(MailConstants.REDIS_MAIL_MESSAGE,MailMessage);
     */
    public MailMessage getMdealerPurConfirmMsg(SysOrder order){
        // 获取订单中采购经销商信息
        SysDealer masterDealer = sysDealerMapper.selectByDealerId(order.getBuyer());
        // 获取订单详情
        LambdaQueryWrapper<SysOrderDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysOrderDetail::getOid,order.getOid());
        List<SysOrderDetail> detailList = sysOrderDetailMapper.selectList(wrapper);
        // 获取商品信息
        StringBuffer sb=new StringBuffer();
        Integer count = 0;
        for (SysOrderDetail detail:detailList) {
            count++;
            SysProduct sysProduct = sysProdService.findProductByProductId(detail.getProductId());
            SysProductSku sysProductSku = sysProdSkuMapper.selectProductSkuByProductId(detail.getProductId());
            sb.append("<tr style=\"padding: 5px 0px 5px 10px;\">");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;\">").append(count).append("</td>");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;\"><img src=\"").append(imgAddress+sysProduct.getPicUrl()).append("\" style=\"width: 100px;height: 100px;\"></td>");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;\">").append(sysProduct.getProductName()).append("</td>");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;\">").append(detail.getQuantity()*sysProductSku.getExchangeNum()).append("</td>");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;text-align: right;\">").append(sysProduct.getPriceMasterDealer()).append("</td>");
            sb.append("</tr>");
        }
        // 根据经销商id查询用户
        SysUser mUser = sysUserMapper.selectByDealerId(masterDealer.getDealerId());
        MailMessage mailMessage = new MailMessage();
        mailMessage.setSubject("Purchase Order Confirmation");
        mailMessage.setEmail(mUser.getAcc());
        String content = "<div style=\"font-size: 10pt; font-family: Verdana,Geneva,sans-serif;\">\n" +
                "    <div id=\"Evo_Oil_Email_Template_web_guide\" style=\"position: absolute; width: 1032px; background-color: rgba(255, 255, 255, 1); overflow: hidden; --web-view-name: Evo Oil Email Template_web_guide; --web-view-id: Evo_Oil_Email_Template_web_guide; --web-scale-on-resize: true; --web-enable-deep-linking: true;\">\n" +
                "        <div id=\"header\" style=\"text-align: center;\"><img id=\"evo_oil_logo\" style=\"position: relative; width: 94.26px; height: 86px; top: 1.5%; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/evo_oil_logo.a4e120fb.png\" /></div>\n" +
                "        <div style=\"position: relative;top: 3%;text-align: center;\"><img id=\"img_login\" style=\"position: relative; width: 812px; height: 272px; top: 3%; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/img_home_banner.981ba427.jpg\" /></div>\n" +
                "        <div id=\"email_content\" style=\"position: relative; width: 80%; left: 10%; top: 5%; overflow: visible;\"><br /><br />\n" +
                "            <div id=\"Hello__name_\" style=\"left: 0px; top: 0px; position: relative; overflow: visible; width: 114px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Hello "+ masterDealer.getDealerName() +",</span></div>\n" +
                "            <br />\n" +
                "            <div id=\"You_have_registered_as_a_deale\" style=\"left: 0px; top: 8%; position: relative; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Thank you for your purchase at Evo Oil Dealership System.<br />We've receive the purchase order with the following details:</span></div>\n" +
                "            <br /><br />\n" +
                "            <div style=\"padding: 20px 0px;\">\n" +
                "                <div>\n" +
                "                    <div>\n" +
                "                        <table class=\"product_table\" style=\"border-collapse: collapse; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px;margin: auto;\">\n" +
                "                            <tr style=\"text-align:left;padding: 5px 0px 5px 10px;\"><th class=\"po_no\" style=\"border-bottom: 1px solid black;padding: inherit;\">No</th><th class=\"po_img\" style=\"border-bottom: 1px solid black;padding: inherit;\">Image</th><th class=\"po_prod_name\" style=\"border-bottom: 1px solid black;padding: inherit; width: 45%\">Product Name</th><th class=\"po_prod_qty\" style=\"border-bottom: 1px solid black;padding: inherit;\">Quantity</th><th class=\"po_prod_price\" style=\"border-bottom: 1px solid black;padding: inherit;text-align: right;\">Price (RM)</th></tr>\n" +
                "                            <!-- 订单数据开始循环 -->\n" +
                "                            <!-- rows of data of the purchase order -->\n" +
                                             sb.toString()+
//                "                            <tr style=\"padding: 5px 0px 5px 10px;\"><td style=\"border-bottom: 1px solid black;padding: inherit;\">1</td><td style=\"border-bottom: 1px solid black;padding: inherit;\"><img src=\"#\" style=\"width: 100px;height: 100px;\"></td><td style=\"border-bottom: 1px solid black;padding: inherit;\">[product_name]</td><td style=\"border-bottom: 1px solid black;padding: inherit;\">[prod_qty]</td><td style=\"border-bottom: 1px solid black;padding: inherit;text-align: right;\">[product_price]</td></tr>\n" +
                "                            <!-- 订单的总额 （包括其他费用比如运输费，调整费等等） -->\n" +
                "                            <!-- total amount of the purchase order (including other fees such as transportation and adjustment) -->\n" +
                "                            <tr  style=\"padding: 5px 0px 5px 10px\"><td colspan=\"4\" style=\"text-align: right;\">Total (RM) : </td><td style=\"text-align: right\">"+ order.getSubFee() +"</td></tr>\n" +
                "                        </table>\n" +
                "                    </div>\n" +
                "                </div>\n" +
                "            </div>\n" +
                "            <br />\n" +
                "            <div id=\"If_you_have_problems_please_co\" style=\"left: 0px; position: relative; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>If you have problems, please copy and paste the below URL into your web browser. <br /><br />"+ problemUrl +"<br /><br />Need help? Contact us at <a href=\"mailto:careline@evooil.com.my\">"+ generalEmail +"</a> <br /><br />Thank you.</span></div>\n" +
                "            <br /><br />\n" +
                "            <div id=\"Best_Regards_Evo_Oil_Dealershi\" style=\"left: 0px; position: relative; overflow: visible; width: 537px; white-space: nowrap; line-height: 20px; margin-top: -1px; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);padding-bottom: 10%\"><span>Best Regards,</span><br /><span style=\"font-style: normal; font-weight: bold;\">Evo Oil Dealership System</span></div>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "</div>";
        mailMessage.setText(content);
        mailMessage.setType(MailConstants.ORDER_TYPE);
        return mailMessage;
    }


    /**
     * 经销商下单后系统会发送 “新采购订单通知” 的邮件至主经销商
     * @param sysOrder 订单
     * @return
     * 调用方式：RedisClient.lpush(MailConstants.REDIS_MAIL_MESSAGE,MailMessage);
     */
    public MailMessage getSendDealerPurMsg(SysOrder sysOrder){
        // 获取商户
        SysDealer dealer = sysDealerMapper.selectByDealerId(sysOrder.getBuyer());
        SysDealer masterDealer = sysDealerMapper.selectByDealerId(sysOrder.getSellers());

        // 通过经销商id查询用户
        SysUser mUser = sysUserMapper.selectByDealerId(masterDealer.getDealerId());

        MailMessage mailMessage = new MailMessage();
        mailMessage.setSubject("Purchase Order from Dealer");
        mailMessage.setEmail(mUser.getAcc());
        String content = "<div id=\"editbody1\">\n" +
                "    <div style=\"font-size: 10pt; font-family: Verdana,Geneva,sans-serif;\">\n" +
                "        <div id=\"Evo_Oil_Email_Template_web_guide\" style=\"position: absolute; width: 1032px; height: 1080px; background-color: rgba(255, 255, 255, 1); overflow: hidden; --web-view-name: Evo Oil Email Template_web_guide; --web-view-id: Evo_Oil_Email_Template_web_guide; --web-scale-on-resize: true; --web-enable-deep-linking: true;\">\n" +
                "            <div id=\"header\" style=\"text-align: center;\"><img id=\"evo_oil_logo\" style=\"position: absolute; width: 94.26px; height: 86px; left: 44.5%; top: 23px; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/evo_oil_logo.a4e120fb.png\" /></div>\n" +
                "            <img id=\"img_login\" style=\"position: absolute; width: 812px; height: 272px; left: 9.7%; top: 136px; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/img_home_banner.981ba427.jpg\" />\n" +
                "            <div id=\"email_content\" style=\"position: absolute; width: 536px; height: 473px; left: 12%; top: 458px; overflow: visible;\"><br /><br />\n" +
                "                <div id=\"Hello__name_\" style=\"left: 0px; top: 0px; position: absolute; overflow: visible; width: 114px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Hello "+ masterDealer.getDealerName() +",</span></div>\n" +
                "                <br />\n" +
                "                <br />\n" +
                "                <div id=\"You_have_registered_as_a_deale\" style=\"left: 0px; top: 81px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>You have just received a purchase order from dealer "+ dealer.getDealerName() +".<br />Click on the button below to check the purchase order details.</span></div>\n" +
                "                <br /><br />\n" +
                "                <div id=\"btn\" style=\"position: absolute; width: 203px; height: 50px; left: 0px; top: 164px; overflow: visible;\">\n" +
                "                    <div id=\"Verify_Your_Email\" class=\"__web-inspector-hide-shortcut__\"><a href=\""+ sysAddress +"\" target=\"_blank\" rel=\"noopener noreferrer\"><button style=\"top: 622px; left: 500px; width: 203px; height: 50px; background: #FDB500 0% 0% no-repeat padding-box; text-align: center; border-radius: 30px; opacity: 1; font: normal normal bold 16px/19px Roboto; font-size: 16px; color: #ffffff;\">View Purchase Order</button></a></div>\n" +
                "                </div>\n" +
                "                <br />\n" +
                "                <div id=\"If_you_have_problems_please_co\" style=\"left: 0px; top: 234px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>If you have problems, please copy and paste the below URL into your web browser. <br /><br />"+ problemUrl +"<br /><br />Need help? Contact us at <a href=\"mailto:careline@evooil.com.my\">"+ generalEmail +"</a> <br /><br />Thank you.</span></div>\n" +
                "                <br /><br /><br /><br />\n" +
                "                <div id=\"Best_Regards_Evo_Oil_Dealershi\" style=\"left: 0px; top: 432px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; line-height: 20px; margin-top: -1px; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Best Regards,</span><br /><span style=\"font-style: normal; font-weight: bold;\">Evo Oil Dealership System</span></div>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "</div>";
        mailMessage.setText(content);
        mailMessage.setType(MailConstants.ORDER_TYPE);
        return mailMessage;
    }


    /**
     * 经销商下单后  系统会发送 “已接受采购订单” 以及采购订单的详情相关的邮件至经销商
     * @return
     * 调用方式：RedisClient.lpush(MailConstants.REDIS_MAIL_MESSAGE,MailMessage);
     */
    public MailMessage getDealerPurConfirmMsg(SysOrder order){
        // 获取订单中采购经销商信息
        SysDealer sysDealer = sysDealerMapper.selectByDealerId(order.getBuyer());
        // 获取订单详情
        LambdaQueryWrapper<SysOrderDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysOrderDetail::getOid,order.getOid());
        List<SysOrderDetail> detailList = sysOrderDetailMapper.selectList(wrapper);
        // 获取商品信息
        StringBuffer sb=new StringBuffer();
        Integer count = 0;
        for (SysOrderDetail detail:detailList) {
            count++;
            SysProduct sysProduct = sysProdService.findProductByProductId(detail.getProductId());
            SysProductSku sysProductSku = sysProdSkuMapper.selectProductSkuByProductId(detail.getProductId());
            sb.append("<tr style=\"padding: 5px 0px 5px 10px;\">");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;\">").append(count).append("</td>");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;\"><img src=\"").append(imgAddress+sysProduct.getPicUrl()).append("\" style=\"width: 100px;height: 100px;\"></td>");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;\">").append(sysProduct.getProductName()).append("</td>");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;\">").append(detail.getQuantity()).append("</td>");
            sb.append("<td style=\"border-bottom: 1px solid black;padding: inherit;text-align: right;\">").append(sysProduct.getPriceDealer()).append("</td>");
            sb.append("</tr>");
        }
        // 通过经销商id查询用户
        SysUser sysUser = sysUserMapper.selectByDealerId(sysDealer.getDealerId());
        MailMessage mailMessage = new MailMessage();
        mailMessage.setSubject("Purchase Order Confirmation");
        mailMessage.setEmail(sysUser.getAcc());
        String content = "<div style=\"font-size: 10pt; font-family: Verdana,Geneva,sans-serif;\">\n" +
                "    <div id=\"Evo_Oil_Email_Template_web_guide\" style=\"position: absolute; width: 1032px; background-color: rgba(255, 255, 255, 1); overflow: hidden; --web-view-name: Evo Oil Email Template_web_guide; --web-view-id: Evo_Oil_Email_Template_web_guide; --web-scale-on-resize: true; --web-enable-deep-linking: true;\">\n" +
                "        <div id=\"header\" style=\"text-align: center;\"><img id=\"evo_oil_logo\" style=\"position: relative; width: 94.26px; height: 86px; top: 1.5%; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/evo_oil_logo.a4e120fb.png\" /></div>\n" +
                "        <div style=\"position: relative;top: 3%;text-align: center;\"><img id=\"img_login\" style=\"position: relative; width: 812px; height: 272px; top: 3%; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/img_home_banner.981ba427.jpg\" /></div>\n" +
                "        <div id=\"email_content\" style=\"position: relative; width: 80%; left: 10%; top: 5%; overflow: visible;\"><br /><br />\n" +
                "            <div id=\"Hello__name_\" style=\"left: 0px; top: 0px; position: relative; overflow: visible; width: 114px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Hello "+ sysDealer.getDealerName() +",</span></div>\n" +
                "            <br />\n" +
                "            <div id=\"You_have_registered_as_a_deale\" style=\"left: 0px; top: 8%; position: relative; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Thank you for your purchase at Evo Oil Dealership System.<br />We've receive the purchase order with the following details:</span></div>\n" +
                "            <br /><br />\n" +
                "            <div style=\"padding: 20px 0px;\">\n" +
                "                <div>\n" +
                "                    <div>\n" +
                "                        <table class=\"product_table\" style=\"border-collapse: collapse; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px;margin: auto;\">\n" +
                "                            <tr style=\"text-align:left;padding: 5px 0px 5px 10px;\"><th class=\"po_no\" style=\"border-bottom: 1px solid black;padding: inherit;\">No</th><th class=\"po_img\" style=\"border-bottom: 1px solid black;padding: inherit;\">Image</th><th class=\"po_prod_name\" style=\"border-bottom: 1px solid black;padding: inherit; width: 45%\">Product Name</th><th class=\"po_prod_qty\" style=\"border-bottom: 1px solid black;padding: inherit;\">Quantity</th><th class=\"po_prod_price\" style=\"border-bottom: 1px solid black;padding: inherit;text-align: right;\">Price (RM)</th></tr>\n" +
                "                            <!-- 订单数据开始循环 -->\n" +
                "                            <!-- rows of data of the purchase order -->\n" +
                                             sb.toString()+
                "                            <!-- 订单的总额 （包括其他费用比如运输费，调整费等等） -->\n" +
                "                            <!-- total amount of the purchase order (including other fees such as transportation and adjustment) -->\n" +
                "                            <tr  style=\"padding: 5px 0px 5px 10px\"><td colspan=\"4\" style=\"text-align: right;\">Total (RM) : </td><td style=\"text-align: right\">"+ order.getSubFee() +"</td></tr>\n" +
                "                        </table>\n" +
                "                    </div>\n" +
                "                </div>\n" +
                "            </div>\n" +
                "            <br />\n" +
                "            <div id=\"If_you_have_problems_please_co\" style=\"left: 0px; position: relative; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>If you have problems, please copy and paste the below URL into your web browser. <br /><br />"+ problemUrl +"<br /><br />Need help? Contact us at <a href=\"mailto:careline@evooil.com.my\">"+ generalEmail +"</a> <br /><br />Thank you.</span></div>\n" +
                "            <br /><br />\n" +
                "            <div id=\"Best_Regards_Evo_Oil_Dealershi\" style=\"left: 0px; position: relative; overflow: visible; width: 537px; white-space: nowrap; line-height: 20px; margin-top: -1px; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);padding-bottom: 10%\"><span>Best Regards,</span><br /><span style=\"font-style: normal; font-weight: bold;\">Evo Oil Dealership System</span></div>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "</div>";
        mailMessage.setText(content);
        mailMessage.setType(MailConstants.ORDER_TYPE);
        return mailMessage;
    }



    /**
     * 发送货品数量低的通知邮件至主经销商 / 持有者
     * @param sysOrder  订单
     * @param stockNum 数量
     * @param productName  产品名
     * @return
     * 调用方式：RedisClient.lpush(MailConstants.REDIS_MAIL_MESSAGE,MailMessage);
     */
    public MailMessage getStockPurMsg(SysOrder sysOrder,Integer stockNum,String productName){
        SysDealer sellerDealer = sysDealerMapper.selectByDealerId(sysOrder.getSellers());
        SysUser sysUser = sysUserMapper.selectByDealerId(sellerDealer.getDealerId());
        MailMessage mailMessage = new MailMessage();
        mailMessage.setSubject("Low Stock Count Reminder");
        mailMessage.setEmail(sysUser.getAcc());
        String content = "<div id=\"editbody1\">\n" +
                "    <div style=\"font-size: 10pt; font-family: Verdana,Geneva,sans-serif;\">\n" +
                "        <div id=\"Evo_Oil_Email_Template_web_guide\" style=\"position: absolute; width: 1032px; height: 1080px; background-color: rgba(255, 255, 255, 1); overflow: hidden; --web-view-name: Evo Oil Email Template_web_guide; --web-view-id: Evo_Oil_Email_Template_web_guide; --web-scale-on-resize: true; --web-enable-deep-linking: true;\">\n" +
                "            <div id=\"header\" style=\"text-align: center;\"><img id=\"evo_oil_logo\" style=\"position: absolute; width: 94.26px; height: 86px; left: 44.5%; top: 23px; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/evo_oil_logo.a4e120fb.png\" /></div>\n" +
                "            <img id=\"img_login\" style=\"position: absolute; width: 812px; height: 272px; left: 9.7%; top: 136px; overflow: visible;\" src=\"http://shop.xiaoka98.cn/static/img/img_home_banner.981ba427.jpg\" />\n" +
                "            <div id=\"email_content\" style=\"position: absolute; width: 536px; height: 473px; left: 12%; top: 458px; overflow: visible;\"><br /><br />\n" +
                "                <div id=\"Hello__name_\" style=\"left: 0px; top: 0px; position: absolute; overflow: visible; width: 114px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Hello "+ sellerDealer.getDealerName() +",</span></div>\n" +
                "                <br />\n" +
                "                <div id=\"Welcome_to_Evo_Oil_Dealership_\" style=\"left: 0px; top: 41px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: bold; font-size: 24px; color: rgba(112, 112, 112, 1);\"><span>Warning!</span></div>\n" +
                "                <br />\n" +
                "                <div id=\"You_have_registered_as_a_deale\" style=\"left: 0px; top: 81px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>There are only "+ stockNum +" stocks left for product [ "+ productName +" ] !<br />Make sure to restock the product before it runs out of stock.</span></div>\n" +
                "                <br /><br />\n" +
                "                <div id=\"btn\" style=\"position: absolute; width: 203px; height: 50px; left: 0px; top: 164px; overflow: visible;\">\n" +
                "                    <div id=\"Verify_Your_Email\" class=\"__web-inspector-hide-shortcut__\"><a href=\""+ sysAddress +"\" target=\"_blank\" rel=\"noopener noreferrer\"><button style=\"top: 622px; left: 500px; width: 203px; height: 50px; background: #FDB500 0% 0% no-repeat padding-box; text-align: center; border-radius: 30px; opacity: 1; font: normal normal bold 16px/19px Roboto; font-size: 16px; color: #ffffff;\">Go To System</button></a></div>\n" +
                "                </div>\n" +
                "                <br />\n" +
                "                <div id=\"If_you_have_problems_please_co\" style=\"left: 0px; top: 234px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>If you have problems, please copy and paste the below URL into your web browser. <br /><br />"+ problemUrl +"<br /><br />Need help? Contact us at <a href=\"mailto:info@myjombeli.com\">"+ generalEmail +"</a> <br /><br />Thank you.</span></div>\n" +
                "                <br /><br /><br /><br />\n" +
                "                <div id=\"Best_Regards_Evo_Oil_Dealershi\" style=\"left: 0px; top: 432px; position: absolute; overflow: visible; width: 537px; white-space: nowrap; line-height: 20px; margin-top: -1px; text-align: left; font-family: Roboto; font-style: normal; font-weight: normal; font-size: 18px; color: rgba(112, 112, 112, 1);\"><span>Best Regards,</span><br /><span style=\"font-style: normal; font-weight: bold;\">Evo Oil Dealership System</span></div>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "</div>";
        mailMessage.setText(content);
        mailMessage.setType(MailConstants.ORDER_TYPE);
        return mailMessage;
    }
}
